package com.course.android.ui.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.course.android.ui.fragment.FunFragment;
import com.course.android.ui.fragment.MilitaryFragment;
import com.course.android.ui.fragment.SchFragment;
import com.course.android.ui.fragment.NewsFragment;
import com.course.android.ui.fragment.SettingFragment;
import com.course.android.ui.fragment.VideoFragment;

import java.util.HashMap;

public class HomePageAdaper extends FragmentPagerAdapter {
    int tabcount;
    public HomePageAdaper(@NonNull FragmentManager fm, int behavior) {
        super(fm, behavior);
        tabcount=behavior;
    }
    HashMap<Integer,Fragment> map = new HashMap<>();


    @NonNull
    @Override
    public Fragment getItem(int position) {


        if (map.containsKey(position)){
            return map.get(position);
        }
        Fragment fragment=null;
        switch (position){
            case 0:
                fragment = new NewsFragment();
                break;
            case 1:
                fragment = new FunFragment();
                break;
            case 2:
                fragment = new MilitaryFragment();
                break;
            case 3:
                fragment = new VideoFragment();
                break;
//            case 4:
//                fragment = new SettingFragment();
//                break;
        }
        if (fragment!=null){
            map.put(position,fragment);
        }
        return fragment;
    }

    @Override
    public int getCount() {
        return tabcount;
    }
}
